package com.lin.simpleboot.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.captcha.generator.RandomGenerator;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.swing.clipboard.ClipboardUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ReferenceUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONStrFormatter;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.lin.simpleboot.model.DateModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.lang.ref.Reference;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;

/**
 * @Description: TestController
 * @Author: linjiayu
 * @Date: 2021/2/9 10:28
 */
@RestController
/*@RequestMapping("/Test")*/
public class testController {

  @GetMapping("/ga")
  public void getAll(HttpServletResponse response) throws IOException {
    // 自定义纯数字的验证码（随机4位数字，可重复）
    RandomGenerator randomGenerator = new RandomGenerator("0oi1I", 4);
    //LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
    ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4);
    captcha.setGenerator(new MathGenerator());
    JSONStrFormatter.format("");
    //captcha.setGenerator(randomGenerator);
    captcha.setBackground(Color.white);
    captcha.setTextAlpha(0.85f);
    // 重新生成code
    captcha.createCode();
    response.getOutputStream().write(captcha.getImageBytes());
    response.flushBuffer();
    //return "success";
  }

  public static void main(String[] args) {
/*    DateModel dateModel = new DateModel();
    dateModel.setName("测试名称");
    dateModel.setCreateTime(new Date());
    System.out.println("hutool:" + JSONUtil.toJsonStr(dateModel));
    System.out.println("fastjson:" + JSON.toJSONStringWithDateFormat(dateModel, "yyyy-MM-dd HH:mm:ss"));
    String json = JSONUtil.parseObj(dateModel).setDateFormat("yyyy-MM-dd HH:mm:ss").toString();
    DateModel dateModel1 = JSONUtil.toBean(json, DateModel.class);
    System.out.println();*/
    Snowflake snowflake = IdUtil.getSnowflake(3232270593L, 1);
    String s = snowflake.nextIdStr();
    System.out.println(s.length());
    System.out.println(NetUtil.getLocalhost().getHostAddress());

  }

}
